home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / TUTORIAL / 1307B.ZIP / BAKCOPY.MOD < prev    next >
Text File  |  1989-01-18  |  7KB  |  200 lines

  1. MODULE BakCopy;
  2.  
  3. (* This program is used to actually copy the files from the fixed  *)
  4. (* disk to the floppy disks.  It uses the file FULLDISK.LST as the *)
  5. (* basis for its copying.  That file is generated using the sister *)
  6. (* program BAKLIST, and after generation, it can be modified with  *)
  7. (* any text editor to allow elimination of any files or directories*)
  8. (* that you do not wish to back up.                                *)
  9. (*                                                                 *)
  10. (*         Copywrite (c) 1987, 1989 - Coronado Enterprises         *)
  11.  
  12. FROM InOut         IMPORT WriteString, WriteCard, WriteLn,
  13.                           Write, Read;
  14. FROM RealInOut     IMPORT WriteReal;
  15. FROM FileSystem    IMPORT Lookup, Close, File, Response, ReadByte;
  16. FROM Strings       IMPORT Copy, Insert, Delete;
  17. FROM DiskDirectory IMPORT CurrentDrive;
  18. FROM SYSTEM        IMPORT ADR;
  19. FROM DirHelps      IMPORT GetDiskStatistics, ChangeToDirectory,
  20.                           CopyFile, FileData, FileDataPointer,
  21.                           ReadFileStats;
  22.  
  23. TYPE CharArray = ARRAY[0..100] OF CHAR;
  24.  
  25. VAR  InputFile         : File;
  26.      SourceDrive       : CHAR;
  27.      SourceFile        : CharArray;
  28.      TargetDrive       : CHAR;
  29.      TargetFile        : CharArray;
  30.      InputLine         : CharArray;
  31.      WorkingDirectory  : CharArray;
  32.      Char              : CHAR;
  33.      Index             : CARDINAL;
  34.      SectorsPerCluster : CARDINAL;
  35.      FreeClusters      : CARDINAL;
  36.      BytesPerSector    : CARDINAL;
  37.      TotalClusters     : CARDINAL;
  38.      ErrorRet          : BOOLEAN;
  39.      ErrorCode         : CARDINAL;
  40.      FileSize          : REAL;
  41.      RoomOnDisk        : REAL;
  42.      RoomOnNewDisk     : REAL;
  43.      DataForFile       : FileData;
  44.      PointToData       : FileDataPointer;
  45.      DiskNumber        : CARDINAL;
  46.      EndOfCopy         : BOOLEAN;
  47.  
  48.  
  49. (* This procedure is used to read in one full line from the input  *)
  50. (* file.                                                           *)
  51.  
  52. PROCEDURE ReadALine;
  53. BEGIN
  54.    Index := 0;
  55.    REPEAT        (* Read one line of input data *)
  56.       ReadByte(InputFile,Char);
  57.       IF Char <> 15C THEN
  58.          InputLine[Index] := Char;
  59.          INC(Index);
  60.       END;
  61.    UNTIL (Index = 100) OR (Char = 12C) OR InputFile.eof;
  62.    InputLine[Index - 1] := 000C;
  63. END ReadALine;
  64.  
  65.  
  66.  
  67. (* This procedure calls the actual copying routine after it checks *)
  68. (* to see if there is enough room on the target floppy.  If there  *)
  69. (* is not, it requests a blank floppy to be loaded.                *)
  70.  
  71. PROCEDURE CopyTheFile;
  72. BEGIN
  73.    Delete(InputLine,0,1);                  (* Remove leading blank *)
  74.    SourceFile := InputLine;
  75.    Insert(SourceDrive,SourceFile,0);
  76.    Insert(':',SourceFile,1);
  77.    TargetFile := InputLine;
  78.    Insert(TargetDrive,TargetFile,0);
  79.    Insert(':',TargetFile,1);
  80.                            (* See if the file will fit on the disk *)
  81.    PointToData := ADR(DataForFile);
  82.    ReadFileStats(SourceFile,TRUE,PointToData,ErrorRet);
  83.    FileSize := PointToData^.Size;
  84.    GetDiskStatistics(TargetDrive,SectorsPerCluster,FreeClusters,
  85.                      BytesPerSector,TotalClusters);
  86.    RoomOnDisk := FLOAT(SectorsPerCluster) *
  87.                  FLOAT(FreeClusters) *
  88.                  FLOAT(BytesPerSector);
  89.    IF RoomOnDisk >= FileSize THEN
  90.       CopyFile(SourceFile,TargetFile,FileSize,ErrorCode);
  91.    ELSIF RoomOnNewDisk >= FileSize THEN
  92.       WriteString("Install a new disk, hit return to continue");
  93.       WriteString(", or hit Q to stop backup");
  94.       WriteLn;
  95.       Read(Char);
  96.       IF Char = 'Q' THEN
  97.          EndOfCopy := TRUE;
  98.       ELSE
  99.          INC(DiskNumber);
  100.          WriteString("Beginning disk number ");
  101.          WriteCard(DiskNumber,3);
  102.          WriteLn;
  103.          ChangeToDirectory(WorkingDirectory,TRUE,ErrorRet);
  104.          GetDiskStatistics(TargetDrive,SectorsPerCluster,FreeClusters,
  105.                            BytesPerSector,TotalClusters);
  106.          RoomOnDisk := FLOAT(SectorsPerCluster) *
  107.                        FLOAT(FreeClusters) *
  108.                        FLOAT(BytesPerSector);
  109.  
  110.          IF RoomOnDisk >= FileSize THEN
  111.             CopyFile(SourceFile,TargetFile,FileSize,ErrorCode);
  112.          ELSE
  113.             WriteString("File too big for this system");
  114.          END;
  115.       END;
  116.    ELSE
  117.       WriteString("File too big for this system");
  118.    END;
  119. END CopyTheFile;
  120.  
  121.  
  122.  
  123. (* This procedure makes the calls to change the directories of both*)
  124. (* the source and target directories.                              *)
  125.  
  126. PROCEDURE ChangeBothDirectories;
  127. BEGIN
  128.    Insert(SourceDrive,InputLine,0);
  129.    Insert(':',InputLine,1);
  130.    ChangeToDirectory(InputLine,FALSE,ErrorRet);
  131.    IF ErrorRet THEN
  132.       WriteString(InputLine);
  133.       WriteString("  Cannot change to source directory");
  134.       WriteLn;
  135.    END;
  136.    InputLine[0] := TargetDrive;
  137.    WorkingDirectory := InputLine;
  138.    ChangeToDirectory(InputLine,TRUE,ErrorRet);
  139.    IF ErrorRet THEN
  140.       WriteString(InputLine);
  141.       WriteString("  Cannot change to target directory");
  142.       WriteLn;
  143.    END;
  144. END ChangeBothDirectories;
  145.  
  146.  
  147.  
  148. BEGIN (* Main program *)
  149.    DiskNumber := 1;
  150.    EndOfCopy := FALSE;
  151.    WriteString("Enter the target drive, one letter ---> ");
  152.    Read(TargetDrive);
  153.    TargetDrive := CAP(TargetDrive);
  154.    Write(TargetDrive);
  155.    WriteLn;
  156.    WriteString("Beginning disk number   1");
  157.    WriteLn;
  158.    GetDiskStatistics(TargetDrive, SectorsPerCluster, FreeClusters,
  159.                      BytesPerSector, TotalClusters);
  160.    IF BytesPerSector > 0 THEN                 (* Valid drive found *)
  161.       RoomOnNewDisk := FLOAT(SectorsPerCluster) *
  162.                        FLOAT(TotalClusters) *
  163.                        FLOAT(BytesPerSector);
  164.       Copy("C:\FULLDISK.LST",0,100,SourceFile);
  165.       CurrentDrive(SourceDrive);       (* Get current drive letter *)
  166.       SourceFile[0] := SourceDrive;  (* Open FULLDISK.LST for read *)
  167.       Lookup(InputFile,SourceFile,FALSE);
  168.       IF InputFile.res = done THEN
  169.          LOOP
  170.             ReadALine;
  171.             IF InputFile.eof THEN
  172.                EXIT;
  173.             ELSE
  174.  
  175.                IF InputLine[0] = ' ' THEN              (* Filename *)
  176.                   CopyTheFile;
  177.                   IF EndOfCopy THEN EXIT END;
  178.                ELSIF InputLine[0] = 000C THEN
  179.                               (* Empty line, not a directory entry *)
  180.                ELSE                                   (* Directory *)
  181.                   ChangeBothDirectories;
  182.                   WriteString(" Directory ---> ");
  183.                   WriteString(InputLine);
  184.                   WriteLn;
  185.                END
  186.             END;
  187.          END; (* LOOP *)
  188.          Close(InputFile);
  189.       ELSE
  190.          WriteString("FULLDISK.LST not available for reading.");
  191.          WriteLn;
  192.          WriteString("Program terminated");
  193.          WriteLn;
  194.       END;
  195.       WriteString("End of Backup copy program");
  196.       WriteLn;
  197.    END; (* Drive test *)
  198. END BakCopy.
  199.  
  200.